﻿<?php 

$filename = $_FILES["file"]["name"];// or /var/www/html/file.docx

$content = read_file_docx($filename); 
if($content !== false) { 

    echo nl2br($content); 
}  
else { 
    echo 'Couldn\'t the file. Please check that file.'; 
} 
function read_file_docx($filename){

    $striped_content = ''; 
    $content = ''; 

    if(!$filename || !file_exists($filename)) return false;  

    $zip = zip_open($filename);

    if (!$zip || is_numeric($zip)) return false; 

    while ($zip_entry = zip_read($zip)) { 

        if (zip_entry_open($zip, $zip_entry) == FALSE) continue; 

        if (zip_entry_name($zip_entry) != "word/document.xml") continue; 

        $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); 

        zip_entry_close($zip_entry); 
    }// end while 

    zip_close($zip); 

    //echo $content; 

    //file_put_contents('1.xml', $content);  

    $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content); 
	$content =  mb_ereg_replace("А","A",$content);
	$content =  mb_ereg_replace("а","a",$content);
	$content =  mb_ereg_replace("Ә","A",$content);
	$content =  mb_ereg_replace("ә","a",$content);
	$content =  mb_ereg_replace("Б","B",$content);
	$content =  mb_ereg_replace("б","b",$content);
	$content =  mb_ereg_replace("В","V",$content);
	$content =  mb_ereg_replace("в","v",$content);
	$content =  mb_ereg_replace("Г","G",$content);
	$content =  mb_ereg_replace("г","g",$content);
	$content =  mb_ereg_replace("Ғ","G",$content);
	$content =  mb_ereg_replace("ғ","g",$content);
	$content =  mb_ereg_replace("Д","D",$content);
	$content =  mb_ereg_replace("д","d",$content);
	$content =  mb_ereg_replace("Е","E",$content);
	$content =  mb_ereg_replace("е","e",$content);
	$content =  mb_ereg_replace("Ё","Yo",$content);
	$content =  mb_ereg_replace("ё","yo",$content);
	$content =  mb_ereg_replace("Ж","J",$content);
	$content =  mb_ereg_replace("ж","j",$content);
	$content =  mb_ereg_replace("З","Z",$content);
	$content =  mb_ereg_replace("з","z",$content);
	$content =  mb_ereg_replace("И","I",$content);
	$content =  mb_ereg_replace("и","i",$content);
	$content =  mb_ereg_replace("Й","Y",$content);
	$content =  mb_ereg_replace("й","y",$content);
	$content =  mb_ereg_replace("К","K",$content);
	$content =  mb_ereg_replace("к","k",$content);
	$content =  mb_ereg_replace("Қ","Q",$content);
	$content =  mb_ereg_replace("қ","q",$content);
	$content =  mb_ereg_replace("Л","L",$content);
	$content =  mb_ereg_replace("л","l",$content);
	$content =  mb_ereg_replace("М","M",$content);
	$content =  mb_ereg_replace("м","m",$content);
	$content =  mb_ereg_replace("Н","N",$content);
	$content =  mb_ereg_replace("н","n",$content);
	$content =  mb_ereg_replace("Ң","N",$content);
	$content =  mb_ereg_replace("ң","n",$content);
	$content =  mb_ereg_replace("О","O",$content);
	$content =  mb_ereg_replace("о","o",$content);
	$content =  mb_ereg_replace("Ө","O",$content);
	$content =  mb_ereg_replace("ө","o",$content);
	$content =  mb_ereg_replace("П","P",$content);
	$content =  mb_ereg_replace("п","p",$content);
	$content =  mb_ereg_replace("Р","R",$content);
	$content =  mb_ereg_replace("р","r",$content);
	$content =  mb_ereg_replace("С","S",$content);
	$content =  mb_ereg_replace("с","s",$content);
	$content =  mb_ereg_replace("Т","T",$content);
	$content =  mb_ereg_replace("т","t",$content);
	$content =  mb_ereg_replace("У","U",$content);
	$content =  mb_ereg_replace("у","u",$content);
	$content =  mb_ereg_replace("Ұ","Ũ",$content);
	$content =  mb_ereg_replace("ұ","ũ",$content);
	$content =  mb_ereg_replace("Ү","Ű",$content);
	$content =  mb_ereg_replace("ү","ű",$content);
	$content =  mb_ereg_replace("Ф","F",$content);
	$content =  mb_ereg_replace("ф","f",$content);
	$content =  mb_ereg_replace("Х","H",$content);
	$content =  mb_ereg_replace("х","h",$content);
	$content =  mb_ereg_replace("Һ","H",$content);
	$content =  mb_ereg_replace("һ","h",$content);
	$content =  mb_ereg_replace("Ц","C",$content);
	$content =  mb_ereg_replace("ц","c",$content);
	$content =  mb_ereg_replace("Ч","C",$content);
	$content =  mb_ereg_replace("ч","c",$content);
	$content =  mb_ereg_replace("Ш","S",$content);
	$content =  mb_ereg_replace("ш","s",$content);
	$content =  mb_ereg_replace("Щ","Sc",$content);
	$content =  mb_ereg_replace("щ","sc",$content);
	$content =  mb_ereg_replace("Ы","I",$content);
	$content =  mb_ereg_replace("ы","ı",$content);
	$content =  mb_ereg_replace("І","I",$content);
	$content =  mb_ereg_replace("і","i",$content);
	$content =  mb_ereg_replace("Э","E",$content);
	$content =  mb_ereg_replace("э","e",$content);
	$content =  mb_ereg_replace("Ю","Yu",$content);
	$content =  mb_ereg_replace("ю","yu",$content);
	$content =  mb_ereg_replace("Я","Ya",$content);
	$content =  mb_ereg_replace("я","ya",$content);
	$content =  mb_ereg_replace("Ь","'",$content);
	$content =  mb_ereg_replace("ь","'",$content);
    $content = str_replace('</w:r></w:p>', "\r\n", $content); 
    $striped_content = strip_tags($content); 

 //   return $striped_content; 
require('tfpdf.php');

$pdf = new tFPDF();
$pdf->AddPage();

// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);

// Load a UTF-8 string from a file and print it//
$txt = $striped_content;
$pdf->Write(8,$txt);

// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(100);


//$pdf->Output();
$pdf->Output('translit.pdf','D'); 
};

?>
